%  P L A C E I N S . T E X        ver 1.0   Feb 15, 1995
%
%  By   Donald Arseneau       <asnd@reg.triumf.ca>
%
%  Insertions that keep their place.
%
%  This small TeX file redefines the output routine (for Plain TeX and 
%  close relatives) so insertions (topins, pageins, etc.) will float 
%  around inside their appropriate section but not intrude into the
%  following section, even though sections do not normally begin a new 
%  page.
%
%  How to use:  First, \input this file (of course!).  Then, at the 
%  beginning of a new section, or at any boundary that insertions should 
%  not cross, put
%                  \par\penalty-20029
%
%  This penalty is a signal to the output routine to perform \supereject
%  if there are insertions held over, but continue on this page if there 
%  are no held insertions.  For your convenience, you should probably put 
%  "\par\penalty-20029" at the beginning of your \section or \startsection 
%  macro.

\catcode`@=11

\edef\noplaceoutput{\the\output}
\output{\placeinsoutput}

\def\placeinsoutput{%
\ifnum\outputpenalty=-20029\relax % section start
 \ifnum\insertpenalties>\z@ % something is being held over, must get it out
  \message{Forcing insertions. \space}%
  \r@ggedbottomtrue \noplaceoutput % performs \supereject
 \else % must rejoin seamlessly:
  \ifvoid\topins\else\insert\topins\unvbox\topins\endinsert\fi
% If you have other floating insertion classes, do the same here.
  \unvbox\@cclv
 \fi
\else % just a regular page break
 \noplaceoutput
\fi
}

\catcode`@=12
\endinput
Test transmission.  ASCII table, 32-54,55-126:  !"#$%&'()*+,-./01234567
89:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
